package com.lj.queue.service;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lj.mp.standard.StandardService;
import com.lj.queue.entity.DelayQueueMessage;
import com.lj.queue.entity.DelayQueueMeta;
import com.lj.queue.enums.DelayQueueMessageStatus;
import com.lj.queue.param.DelayQueueMessagePageParam;
import com.lj.queue.param.DelayQueueMessageSaveParam;
import com.lj.queue.param.DelayQueueMessageUpdateParam;
import com.lj.queue.result.DelayQueueMessageInfoResult;
import com.lj.queue.result.DelayQueueMessagePageResult;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 延迟队列消息表 服务类
 * </p>
 *
 * @author lj
 * @since 2025-07-16 18:30:18
 */
public interface DelayQueueMessageService extends StandardService<DelayQueueMessage> {

    IPage<DelayQueueMessagePageResult> page(DelayQueueMessagePageParam param);

    DelayQueueMessageInfoResult info(Long id);

    void save(DelayQueueMessageSaveParam param);

    boolean pushMessage(DelayQueueMeta queueMeta, List<DelayQueueMessage> messageList);

    void update(DelayQueueMessageUpdateParam param);

    void delete(List<Long> ids);

    void importExcel(Long queueId, InputStream in);

    void importExcelTemplate(OutputStream out);

    void exportExcel(DelayQueueMessagePageParam param, OutputStream out);

    default void updateStatus(Collection<Long> ids, DelayQueueMessageStatus status) {
        if (CollUtil.isEmpty(ids) || status == null) {
            return;
        }
        update(lambdaUpdateWrapper()
                .set(DelayQueueMessage::getStatus, status)
                .in(DelayQueueMessage::getId, ids));
    }

    default boolean updateStatus(Long id, DelayQueueMessageStatus status) {
        if (id == null || status == null) {
            return false;
        }
        return update(lambdaUpdateWrapper()
                .set(DelayQueueMessage::getStatus, status)
                .ne(DelayQueueMessage::getStatus, status)
                .eq(DelayQueueMessage::getId, id));
    }
}
